package java111;

import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Day22 {
    //https://www.nowcoder.com/questionTerminal/b2b816e20e8343b49abbaf493886ce26
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String str1 = in.next();
        String str2 = in.next();
        int res = Integer.MAX_VALUE;
        int len1 = str1.length(), len2 = str2.length();
        for(int i = 0; i <= len2 - len1; i++){
            int j = 0, k = i, tmp = 0;;
            while(j < str1.length()){
                if(str1.charAt(j) != str2.charAt(k)){
                    tmp++;
                }
                j++;
                k++;
            }
            res = Math.min(res, tmp);
        }
        System.out.println(res);
    }

    //https://www.nowcoder.com/questionTerminal/c55f4f15cc3f4ff0adede7f9c69fa0c1
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[] arr = new int[n];
            TreeSet<Integer> set = new TreeSet<>();
            int i = 0;
            for(; i < n; i++){
                arr[i] = in.nextInt();
                set.add(arr[i]);
            }
            i = 0;
            for(int tmp : set){
                arr[i++] = tmp;
            }
            int j = 0;
            for(; j < i-1; j++){
                while(arr[j] < arr[j+1]){
                    arr[j] *= 2;
                }
                if(arr[j] > arr[j+1]){
                    System.out.println("NO");
                    break;
                }
            }
            if(j == i-1){
                System.out.println("YES");
            }
        }
    }

    //https://www.nowcoder.com/practice/c990bd0bf8e04bfbb19c0964401c8f77?tpId=230&tqId=40434&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int v = in.nextInt();
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int[][] dp = new int[n+1][v+1];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= v; j++){
                dp[i][j] = dp[i-1][j];
                if(j-arr[i-1] >= 0){
                    dp[i][j] = Math.max(dp[i][j], dp[i-1][j-arr[i-1]] + arr[i-1]);
                }
            }
        }
        System.out.println(v-dp[n][v]);
    }
}
